package com.sz.pojo.frame;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * 用户
 * 
 * @author zhqy
 * 
 */
@Entity
@Table(name = "core_user")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "pojoCache")
public class User extends BaseObject<User> {

	private static final long serialVersionUID = 1L;

	/** 正常 */
	public static final int NORMAL = 0;
	/** 停用 */
	public static final int DISABLE = 1;
	/** 锁定 */
	public static final int LOCKED = 2;
	/** 删除 */
	public static final int DELETE = 3;

	private static String[] userStatusName = { "正常", "停用", "锁定", "删除" };

	private String name;

	private String username;

	private String password;
	/** 密码盐 */
	private String pwdSerial;
	/** 用户状态 **/
	private Integer userStatus;
	/** 电话 **/
	private String telphone;
	/** 手机 **/
	private String cellphone;
	/** 职位 **/
	private String position;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(nullable = false, unique = true)
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	/** 密码盐 */
	public String getPwdSerial() {
		return pwdSerial;
	}

	/** 密码盐 */
	public void setPwdSerial(String pwdSerial) {
		this.pwdSerial = pwdSerial;
	}

	public Integer getUserStatus() {
		return userStatus;
	}

	public void setUserStatus(Integer userStatus) {
		this.userStatus = userStatus;
	}

	@Transient
	public String getUserStatusName() {
		if (userStatus == null) {
			return "出错啦！";
		}
		return userStatusName[userStatus];
	}

	public String getPosition() {
		return position;
	}

	public void setPosition(String position) {
		this.position = position;
	}

	public String getTelphone() {
		return telphone;
	}

	public void setTelphone(String telphone) {
		this.telphone = telphone;
	}

	@Column(nullable = false, unique = true)
	public String getCellphone() {
		return cellphone;
	}

	public void setCellphone(String cellphone) {
		this.cellphone = cellphone;
	}


	public boolean equals(Object object) {
		if (this == object) return true;
		if (!(object instanceof User)) return false;
		if (!super.equals(object)) return false;

		User user = (User) object;

		if (name != null ? !name.equals(user.name) : user.name != null) return false;
		if (!username.equals(user.username)) return false;
		if (!password.equals(user.password)) return false;
		if (!pwdSerial.equals(user.pwdSerial)) return false;
		if (!userStatus.equals(user.userStatus)) return false;
		if (telphone != null ? !telphone.equals(user.telphone) : user.telphone != null) return false;
		if (cellphone != null ? !cellphone.equals(user.cellphone) : user.cellphone != null) return false;
		if (position != null ? !position.equals(user.position) : user.position != null) return false;

		return true;
	}

	public int hashCode() {
		int result = super.hashCode();
		result = 31 * result + (name != null ? name.hashCode() : 0);
		result = 31 * result + username.hashCode();
		result = 31 * result + password.hashCode();
		result = 31 * result + pwdSerial.hashCode();
		result = 31 * result + userStatus.hashCode();
		result = 31 * result + (telphone != null ? telphone.hashCode() : 0);
		result = 31 * result + (cellphone != null ? cellphone.hashCode() : 0);
		result = 31 * result + (position != null ? position.hashCode() : 0);
		return result;
	}


	@Override
	public String toString() {
		return "User{" +
				"name='" + name + '\'' +
				", username='" + username + '\'' +
				", password='" + password + '\'' +
				", pwdSerial='" + pwdSerial + '\'' +
				", userStatus=" + userStatus +
				", telphone='" + telphone + '\'' +
				", cellphone='" + cellphone + '\'' +
				", position='" + position + '\'' +
				'}';
	}
}
